/*
 * Sesame Inc.
 * Copyright (c) 2009 All Rights Reserved.
 */
package com.sesame.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;
import com.sesame.domain.User;
import com.sesame.service.ContactService;
import com.sesame.service.UserService;

/**
 * @author voidman
 * 
 */
public class NewFriendController extends AbstractController {

    private ContactService contactService;
    private UserService userService;

    public void setContactService(ContactService contactService) {
        this.contactService = contactService;
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    protected ModelAndView handleRequestInternal(HttpServletRequest request,
            HttpServletResponse reponse) throws Exception {

        Integer user1Id = (Integer) request.getSession().getAttribute("userId");
        Integer user2Id = Integer.parseInt(request.getParameter("user2Id"));
        String headPic = userService.showUser(user2Id).getHeadPic();
        contactService.makeFriend(user1Id, user2Id, headPic);

        return new ModelAndView("redirect:userHome.html?userId=" + user2Id);

    }

}